# -*- coding:utf-8 -*-
import Pluto,struct,os,fnmatch

def walk(adr):
    mylist=[]
    for root,dirs,files in os.walk(adr):
        mylist.append(root)
    return mylist

dirlist=walk('mst')[1:]
for dirs in dirlist:
    print dirs
    fl=os.listdir(dirs)
    tar=open('packfiles\\'+dirs.split('\\')[1]+'.mst','wb')
    tar.write('DMST')
    tar.write(struct.pack('i',len(fl)/2))
    tar.seek(8+len(fl)/2*4)
    offsetlist=[]
    for fn in fl:
        if not fnmatch.fnmatch(fn,'*.bin'):
            continue
        offsetlist.append(tar.tell())
        fp=open(dirs+'\\'+fn,'rb')
        data=fp.read()
        fp.close()
        tar.write(data)
    tar.seek(8)
    for offset in offsetlist:
        tar.write(struct.pack('i',offset))
    tar.close()